package mvc.model.dao.impl;

import mvc.common.BaseDao;
import mvc.model.dao.P_infoDao;
import mvc.model.pojos.P_infoBean;
import mvc.model.vo.Color_Path;
import mvc.model.vo.Setmeal;

import java.util.List;

public class P_infoDaoImpl implements P_infoDao {
    private static final BaseDao baseDao = new BaseDao();
    @Override
    public P_infoBean query(int number, int flag) {
        String sql = "select * from p_info where number = ?;";
        List<P_infoBean> query = baseDao.query(sql, P_infoBean.class, number);
        return query.isEmpty() ? null : query.get(0);
    }

    @Override
    public P_infoBean queryid(int number) {
        String sql = "select * from p_info where number = ?";
        List<P_infoBean> query = baseDao.query(sql,P_infoBean.class,number);
        return query.isEmpty() ? null : query.get(0);
    }

    @Override
    public Color_Path queryPath(int pid, int cid) {
        String sql = "select cid,color,pnumber,path from p_info p join p_p pp on p.pid = pp.pid " +
                "join ppicture pic on pp.pnumber = pic.pnumber where pid = ? and cid = ?";
        List<Color_Path> query = baseDao.query(sql,Color_Path.class,pid,cid);
        return query.isEmpty() ? null : query.get(0);
    }

    @Override
    public List<Setmeal> queryMeal(int pid) {
        String sql = "select sid,isid,pid,price from setmeal s join sminfo sm on s.isid = sm.isid where pid = ?";
        return baseDao.query(sql,Setmeal.class,pid);
    }


}
